package com.zhaorujie.rpc.core.utils;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 赵汝杰
 * @version v1.0
 * @description ThreadPoolUtil
 * @date 2024/3/5
 **/
public class ThreadPoolUtil {

    public static ThreadPoolExecutor createServiceThreadPool(int corePoolSize, int maxPoolSize) {
        return new ThreadPoolExecutor(corePoolSize,
                maxPoolSize,
                60,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(1000),
                new ThreadFactory() {
                    @Override
                    public Thread newThread(Runnable r) {
                        return new Thread(r, "rpc, serverHandlerPool-" + r.hashCode());
                    }
                },
                new ThreadPoolExecutor.CallerRunsPolicy());
    }
}
